package com.ruoyi.machine.advanced.repair.register.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.machine.advanced.repair.register.domain.RepairRegister;
import com.ruoyi.machine.advanced.repair.register.mapper.RepairRegisterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备维修登记表
 * 业务层处理
 */
@Service
public class RepairRegisterService implements IRepairRegisterService {

    @Autowired
    private RepairRegisterMapper repairRegisterMapper;

    /**
     * 查找设备维修登记
     * @param repairRegister
     * @return
     */
    @Override
    public List<RepairRegister> selectRepairRegisterList(RepairRegister repairRegister) {
        return repairRegisterMapper.selectRepairRegisterList(repairRegister);
    }

    /**
     * 根据Id查找设备维修登记
     * @param repairRegisterId
     * @return
     */
    @Override
    public RepairRegister selectRepairRegisterById(String repairRegisterId) {
        return repairRegisterMapper.selectRepairRegisterById(repairRegisterId);
    }

    /**
     * 添加设备维修登记
     * @param repairRegister
     * @return
     */
    @Override
    public int insertRepairRegister(RepairRegister repairRegister) {
        if (StringUtils.isNotNull(repairRegisterMapper.selectRepairRegisterById(repairRegister.getRepairRegisterId()))) {
            //存在
            return 0;
        }
        //不存在
        return repairRegisterMapper.insertRepairRegister(repairRegister);
    }

    /**
     * 更新设备维修登记
     * @param repairRegister
     * @return
     */
    @Override
    public int updateRepairRegister(RepairRegister repairRegister) {
        if (!StringUtils.isNotNull(repairRegisterMapper.selectRepairRegisterById(repairRegister.getRepairRegisterId()))) {
            //不存在
            return 0;
        }
        //存在
        return repairRegisterMapper.updateRepairRegister(repairRegister);
    }

    /**
     * 删除设备维修登记
     * 仅修改删除标志
     * @param repairRegister
     * @return
     */
    @Override
    public int updateRepairRegisterDeleteFlag(RepairRegister repairRegister) {
        return repairRegisterMapper.updateRepairRegisterDeleteFlag(repairRegister);
    }
}
